#ifndef QUEUE_H
#define QUEUE_H

#include <QObject>
#include <QList>
#include <QVariant>
#include <QTimer>
#include "QTwitLib.h"

#define DEFAULT_TIMEOUT_TIME 30000
#define DEFAULT_QUEUE_MAX 10

class Queue : public QObject {
    Q_OBJECT
public:
    Queue(QObject *parent = 0);
    ~Queue();

    enum STATE
    {
        NOT_RUNNING,
        FREEZE,
        WAIT_ANSWER
    };

public slots:
        void OKanswer();
        void addCommand(const Returnables::RequestId &command, QList<QVariant> param);
        void reset();

private:
        QList<Returnables::RequestId> commandsQueue;
        QList< QList<QVariant> > paramQueue;
        Queue::STATE state;
        Returnables::RequestId currentCommand;
        QList<QVariant> currentParam;
        QTimer *timeOutTimer;
        void getCommand();
        int errorCounter;

private slots:
        void noOKanswer();

signals:
        void returnCommand(Returnables::RequestId, QList<QVariant>);
        void networkError();
        void lostAnswer();
        void stateChanged(Queue::STATE state);
};

#endif // QUEUE_H
